package cc.xiaolv123.vvvdjToBaidu.controller;

import cc.xiaolv123.vvvdjToBaidu.util.BaiduwangpanUtil;
import cc.xiaolv123.vvvdjToBaidu.util.VvvdjUtil;
import cc.xiaolv123.vvvdjToBaidu.util.HttpContextUtils;
import cc.xiaolv123.vvvdjToBaidu.vo.DJInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@RestController
@RequestMapping("/collect")
public class CollectController {

    @Autowired
    private VvvdjUtil vvvdjUtil;
    @Autowired
    private BaiduwangpanUtil baiduwangpanUtil;

    @GetMapping("/code")
    public void code() throws IOException {
        String code = baiduwangpanUtil.code();
        HttpServletResponse response = HttpContextUtils.getHttpServletResponse();
        PrintWriter writer = response.getWriter();
        writer.write("<script>");
        writer.write("window.location.href='" + code + "'");
        writer.write("</script>");
    }

    //采集类型 1华语Remix
    @GetMapping("/huayu")
    public String huayu(int pageNum) throws IOException {
        for (int k = 1; k <= pageNum; k++) {
            List<DJInfoVO> djInfoVOList = vvvdjUtil.collectByPage(1, k);
            for (DJInfoVO djInfoVO : djInfoVOList) {
                vvvdjUtil.downloadToDisk(djInfoVO);
            }
        }
        return "success";
    }

    //采集类型 4外语Remix
    @GetMapping("/waiyu")
    public String waiyu(int pageNum) throws IOException {
        for (int k = 1; k <= pageNum; k++) {
            List<DJInfoVO> djInfoVOList = vvvdjUtil.collectByPage(4, k);
            for (DJInfoVO djInfoVO : djInfoVOList) {
                vvvdjUtil.downloadToDisk(djInfoVO);
            }
        }
        return "success";
    }

    //采集类型 3慢歌连版
    @GetMapping("/slow")
    public String slow(int pageNum) throws IOException {
        for (int k = 1; k <= pageNum; k++) {
            List<DJInfoVO> djInfoVOList = vvvdjUtil.collectByPage(3, k);
            for (DJInfoVO djInfoVO : djInfoVOList) {
                vvvdjUtil.downloadToDisk(djInfoVO);
            }
        }
        return "success";
    }

    //采集类型 2串烧舞曲
    @GetMapping("/bbq")
    public String bbq(int pageNum) throws IOException {
        for (int k = 1; k <= pageNum; k++) {
            List<DJInfoVO> djInfoVOList = vvvdjUtil.collectByPage(2, k);
            for (DJInfoVO djInfoVO : djInfoVOList) {
                vvvdjUtil.downloadToDisk(djInfoVO);
            }
        }
        return "success";
    }
}
